function goadminAjax(json){
	jQuery.ajax({
		type:"post",
		url:"http://127.0.0.1:8080/webXiangmu/AdminAjaxServlet",
		data:JSON.stringify(json),
		dataType:"json",
		success:function(message){
			var instruct = message.instruct;
			var page = "<div id = \"barcon\" class=\"barcon\">"+
			"<div id = \"barcon1\" class=\"barcon1\"></div>"+
			"<div id=\"barcon2\" class=\"barcon2\">"+
				"<ul>"+
					"<li><a href=\"###\" id=\"firstPage\">首页</a></li>"+
					"<li><a href=\"###\" id=\"prePage\">上一页</a></li>"+
					"<li><a href=\"###\" id=\"nextPage\">下一页</a></li>"+
					"<li><a href=\"###\" id=\"lastPage\">尾页</a></li>"+
					"<li><select id=\"jumpWhere\"></select></li>"+
					"<li><a href=\"###\" id=\"jumpPage\" onclick=\"jumpPage()\">跳转</a></li>"+
				"</ul></div></div>";
			if(instruct=="reviseMovie"){
				var movAlJson = JSON.parse(message.msg);
				//alert(movAlJson);
				var makemessage = document.getElementById("makemessage");
				var messageHtml="<table id=\"table\" class=\"table\">"+
			"<tr class=\"thead\">"+
				"<td class=\"id\">电影ID</td>"+
				"<td class=\"name\">电影名称</td>"+
				"<td>导演</td>"+
				"<td>主演</td>"+
				"<td class=\"date\">上映时间</td>"+
				"<td class=\"time\">添加时间</td>"+
				"<td class=\"work\">操作</td>"
				"</tr>";
				for(var i in movAlJson){
					messageHtml = messageHtml+
					"<tr class=\"tcom\">"+
					"<td class=\"id\">"+
						"<p>"+movAlJson[i].mid+"</p>"+
					"</td>"+
					"<td><p>"+movAlJson[i].mname+"</p></td>"+
					"<td><p>"+movAlJson[i].daoYan+"</p></td>"+
					"<td><p>"+movAlJson[i].zhuYan+"</p></td>"+
					"<td class=\"date\"><p>"+movAlJson[i].showTime+"</p></td>"+
					"<td class=\"time\"><p>"+movAlJson[i].addTime+"</p></td>"+
					"<td class=\"work\">"+
						"<button class=\"delete\"id=\"dellet,"+movAlJson[i].mid+"\" onclick=\"delMovie("+movAlJson[i].mid+")\">删除</button>"+
						"<button class=\"revise\"id=\"revise,"+movAlJson[i].mid+"\" onclick=\"reviseThisMov("+movAlJson[i].mid+")\">修改</button>"+
					"</td></tr>" ;
				}
				messageHtml = messageHtml+"</table>";
				messageHtml = messageHtml+page;
				makemessage.innerHTML=messageHtml;
				loadjscssfile("js/paging.js","js");
			}else if(instruct == "reviseReview"){
				var revAlJson = JSON.parse(message.msg);
				//alert(revAlJson);
				var makemessage = document.getElementById("makemessage");
				var messageHtml="<table id=\"table\" class=\"table\">"+
				"<tr class=\"thead\">"+
				"<td class=\"id\">影评ID</td>"+
				"<td class=\"name\">影评标题</td>"+
				"<td class=\"id\">电影ID</td>"+
				"<td>电影名称</td>"+
				"<td>影评作者</td>"+
				"<td>影评内容</td>"+
				"<td class=\"work\">操作</td>"
				"</tr>";
				for(var i in revAlJson){
					messageHtml = messageHtml+
					"<tr class=\"tcom\">"+
					"<td class=\"id\">"+
						"<p>"+revAlJson[i].rId+"</p>"+
					"</td>"+
					"<td><p>"+revAlJson[i].rtitle+"</p></td>"+
					"<td class=\"id\"><p>"+revAlJson[i].mId+"</p></td>"+
					"<td><p>"+revAlJson[i].mname+"</p></td>"+
					"<td><p>"+revAlJson[i].author+"</p></td>"+
					"<td><p>"+revAlJson[i].rcontent+"</p></td>"+
					"<td class=\"work\">"+
						"<button class=\"delete\"id=\"dellet,"+revAlJson[i].rid+"\" onclick=\"delReview("+revAlJson[i].rId+")\">删除</button>"+
						"<button class=\"revise\"id=\"revise,"+revAlJson[i].rid+"\" onclick=\"revisethisRev("+revAlJson[i].rId+")\">修改</button>"+
					"</td></tr>" ;
				}
				messageHtml = messageHtml+"</table>";
				messageHtml = messageHtml+page;
				makemessage.innerHTML=messageHtml;
				loadjscssfile("js/paging.js","js");
			}else if(instruct =="reviseComment"){
				var comAlJson = JSON.parse(message.msg);
				//alert(comAlJson);
				var makemessage = document.getElementById("makemessage");
				var messageHtml="<table id=\"table\" class=\"table\">"+
				"<tr class=\"thead\">"+
				"<td class=\"id\">回复ID</td>"+
				"<td class=\"id\">影评ID</td>"+
				"<td class=\"id\">用户ID</td>"+
				"<td>用户昵称</td>"+
				"<td>回复内容</td>"+
				"<td class=\"time\">回复时间</td>"+
				"<td class=\"work\">操作</td>"
				"</tr>";
				for(var i in comAlJson){
					messageHtml = messageHtml+
					"<tr class=\"tcom\">"+
					"<td class=\"id\">"+
						"<p>"+comAlJson[i].cId+"</p>"+
					"</td>"+
					"<td class=\"id\"><p>"+comAlJson[i].rId+"</p></td>"+
					"<td class=\"id\"><p>"+comAlJson[i].uId+"</p></td>"+
					"<td><p>"+comAlJson[i].nicname+"</p></td>"+
					"<td><p>"+comAlJson[i].ccontent+"</p></td>"+
					"<td class=\"time\"><p>"+comAlJson[i].ctime+"</p></td>"+
					"<td class=\"work\">"+
						"<button class=\"delete\"id=\"dellet,"+comAlJson[i].cId+"\" onclick=\"delComment("+comAlJson[i].cId+")\">删除</button>"+
					"</td></tr>" ;
				}
				messageHtml = messageHtml+"</table>";
				messageHtml = messageHtml+page;
				makemessage.innerHTML=messageHtml;
				loadjscssfile("js/paging.js","js");
			}else if(instruct=="reviseNotice"){
				var notAlJson = JSON.parse(message.msg);
				//alert(revAlJson);
				var makemessage = document.getElementById("makemessage");
				var messageHtml="<table id=\"table\" class=\"table\">"+
				"<tr class=\"thead\">"+
				"<td class=\"id\">公告ID</td>"+
				"<td>公告标题</td>"+
				"<td>公告内容</td>"+
				"<td class=\"time\">发布时间</td>"+
				"<td class=\"work\">操作</td>"
				"</tr>";
				for(var i in notAlJson){
					messageHtml = messageHtml+
					"<tr class=\"tcom\">"+
					"<td class=\"id\">"+
						"<p>"+notAlJson[i].nid+"</p>"+
					"</td>"+
					"<td><p>"+notAlJson[i].ntitle+"</p></td>"+
					"<td><p>"+notAlJson[i].ncontent+"</p></td>"+
					"<td class=\"time\"><p>"+notAlJson[i].ntime+"</p></td>"+
					"<td class=\"work\">"+
						"<button class=\"delete\"id=\"dellet,"+notAlJson[i].nid+"\" onclick=\"delNotice("+notAlJson[i].nid+")\">删除</button>"+
						"<button class=\"revise\"id=\"revise,"+notAlJson[i].nid+"\" onclick=\"revisethisNot("+notAlJson[i].nid+")\">修改</button>"+
					"</td></tr>" ;
				}
				messageHtml = messageHtml+"</table>";
				messageHtml = messageHtml+page;
				makemessage.innerHTML=messageHtml;
				loadjscssfile("js/paging.js","js");
			}else if(instruct == "reviseUser"){
				var useAlJson = JSON.parse(message.msg);
				//alert(revAlJson);
				var makemessage = document.getElementById("makemessage");
				var messageHtml="<table id=\"table\" class=\"table\">"+
				"<tr class=\"thead\">"+
				"<td class=\"id\">用户ID</td>"+
				"<td>账号</td>"+
				"<td>密码</td>"+
				"<td>昵称</td>"+
				"<td>电话</td>"+
				"<td>qq</td>"+
				"<td class=\"time\">注册时间</td>"+
				"<td class=\"work\">操作</td>"
				"</tr>";
				for(var i in useAlJson){
					messageHtml = messageHtml+
					"<tr class=\"tcom\">"+
					"<td class=\"id\">"+
						"<p>"+useAlJson[i].uId+"</p>"+
					"</td>"+
					"<td><p>"+useAlJson[i].uname+"</p></td>"+
					"<td><p>"+useAlJson[i].password+"</p></td>"+
					"<td><p>"+useAlJson[i].nicname+"</p></td>"+
					"<td><p>"+useAlJson[i].tel+"</p></td>"+
					"<td><p>"+useAlJson[i].qq+"</p></td>"+
					"<td class=\"time\"><p>"+useAlJson[i].regTime+"</p></td>"+
					"<td class=\"work\">"+
						"<button class=\"delete\" onclick=\"delUser("+useAlJson[i].uId+")\">删除</button>"+
					"</td></tr>" ;
				}
				messageHtml = messageHtml+"</table>";
				messageHtml = messageHtml+page;
				makemessage.innerHTML=messageHtml;
				loadjscssfile("js/paging.js","js");
			}else if(instruct=="delUser"){//删除用户

				alert(message.msg);
				reviseUser();
			}else if(instruct=="delNotice"){//删除公告
				alert(message.msg);
				reviseNotice();
			}else if(instruct=="delComment"){//删除回复
				alert(message.msg);
				reviseComment();
			}else if(instruct=="delReview"){//删除影评
				alert(message.msg);
				reviseReview();
			}else if(instruct=="delMovie"){//删除电影
				alert(message.msg);
				reviseMovie();
			}else if(instruct=="revisethisNot"){//修改指定公告
				var revNot = JSON.parse(message.msg);
				//加载form表单页面
				addNotice('reviseNotice');
				//给对应输入框赋值
				var nidval = document.getElementById("nid");
				var noticenameval = document.getElementById("noticename");
				var noticecon = document.getElementById("noticecon");
				noticecon.value = revNot.ncontent;
				noticenameval.value = revNot.ntitle;
				nidval.value = revNot.nid;
			}else if(instruct == "addReview"){//添加影评中的电影选项
				var movName = JSON.parse(message.msg);
				var movieSel = document.getElementById("movieSel");
				var movieSelHtml = "";
				for(var i in movName){
					movieSelHtml = movieSelHtml+"<option value=\""+movName[i].mid+","+movName[i].mname+"\">"+movName[i].mname+"</option>";
				}
				movieSel.innerHTML = movieSelHtml;
			}else if(instruct == "reviseThisRev"){//修改指定影评
				var revRev = JSON.parse(message.msg);
				//alert("revRev="+message.msg);
				//加载form表单页面
				addReview('reviseReview');
				//给对应输入框赋值
				var reviewTitle = document.getElementById("reviewTitle");
				var rcontent = document.getElementById("rcontent");
				var author = document.getElementById("author");
				var revrid = document.getElementById("rid");
				reviewTitle.value = revRev.rtitle;
				rcontent.value = revRev.rcontent;
				author.value = revRev.author;
				revrid.value = revRev.rId;
			}else if(instruct =="revisethisMov"){
				var revMov = JSON.parse(message.msg);
				//加载form表单页面
				addMovie('reviseMovie');
				//给对应输入框赋值
				var mname = document.getElementById("mname");
				var type = document.getElementById("type");
				var daoyan = document.getElementById("daoyan");
				var zhuyan = document.getElementById("zhuyan");
				var showtime = document.getElementById("showtime");
				var mcontent = document.getElementById("mcontent");
				var mid = document.getElementById("mid");
				mname.value = revMov.mname;
				type.value = revMov.type;
				daoyan.value = revMov.daoYan;
				zhuyan.value = revMov.zhuYan;
				showtime.value = revMov.showTime;
				mcontent.value = revMov.mcontent;
				mid.value = revMov.mid;
			}else if(instruct == "wrong"){
				alert("服务器接收instruct错误");
			}else{
				alert("adminAjax.js接收instruct错误，没有"+instruct);
			}
		},
		error:function(message){
			alert("ajax返回错误");
		}
	});
}
//删除用户
function delUser(uid){
	var json={
			instruct:"delUser",
			uid:uid
	}
	goadminAjax(json);
}
//删除公告
function delNotice(nid){
	var json={
			instruct:"delNotice",
			nid:nid
	}
	goadminAjax(json);
}
//删除评论
function delComment(cid){
	var json={
			instruct:"delComment",
			cid:cid
	}
	goadminAjax(json);
}
//删除影评
function delReview(rid){
	var json={
			instruct:"delReview",
			rid:rid
	}
	goadminAjax(json);
}
//删除电影
function delMovie(mid){
	var json={
			instruct:"delMovie",
			mid:mid
	}
	goadminAjax(json);
}

//修改指定公告
function revisethisNot(nid){
	var json={
			instruct:"revisethisNot",
			nid:nid
	}
	goadminAjax(json);
}
//修改指定影评
function revisethisRev(rid){
	var json={
			instruct:"revisethisRev",
			rid:rid
	}
	goadminAjax(json);
}
//修改指定电影
function reviseThisMov(mid){
	var json={
			instruct:"revisethisMov",
			mid:mid
	}
	goadminAjax(json);
}

//动态加载js/css
function loadjscssfile(filename, filetype){
	if(filetype == "js"){//判定文件类型
		var fileref = document.createElement('script');//创建标签
		fileref.setAttribute("type","text/javascript");//定义属性type的值为text/javascript
		fileref.setAttribute("src",filename);//文件的地址
	}
	else if (filetype == "css"){//判定文件类型
		var fileref = document.createElement("link");
		fileref.setAttribute("rel","stylesheet");
		fileref.setAttribute("type","text/css");
		fileref.setAttribute("href",filename);
	}
	if(typeof fileref !="undefined")
		document.getElementsByTagName("head")[0].appendChild(fileref);
}
